worker_processes 1;

events { worker_connections 1024; }

http {
    upstream blue_customer {
        server blue_app_customers:8000;
        #server blue_app_accounts:8080;
    }

    upstream green_customer {
        server green_app_customers:8000;
        #server green_app_accounts:8080;
    }

    upstream blue_accounts {
        #server blue_app_customers:8000;
        server blue_app_accounts:8080;
    }

    upstream green_accounts {
        #server green_app_customers:8000;
        server green_app_accounts:8080;
    }

    server {
        listen 80;

        location / {
            proxy_pass http://blue_customer;
        }

        location /green {
            rewrite ^/green(/.*)$ $1 break;  # удаление "green" из URL
            proxy_pass http://green_customer;
        }

        location /accounts {
            proxy_pass http://blue_accounts;
        }

        location /green/accounts {
            rewrite ^/green(/.*)$ $1 break;  # удаление "green" из URL
            proxy_pass http://green_accounts;
        }
    }
}

stream {
    server {
        listen 5433;

        proxy_pass db_cust:5432;
    }
}
